package com.qixiucoding.aspect;

import com.qixiucoding.annotation.DoneTime;
import com.qixiucoding.controller.IndexController;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import java.util.Date;

@Aspect
@Component
public class DoneTimeAspect {

    @Around("@annotation(doneTime)")
    public Object around(ProceedingJoinPoint joinPoint, DoneTime doneTime) throws Throwable {
        for (Object arg : joinPoint.getArgs()) {
            System.out.println(arg.toString());
        }
        System.out.println(joinPoint.getSignature());
        IndexController target = (IndexController) joinPoint.getTarget();
        target.print();
        System.out.println(doneTime.param());
        System.out.println("方法开始时间是:"+new Date());
        Object o = joinPoint.proceed();
        System.out.println("方法结束时间是:"+new Date()) ;
        // System.out.println("dsd"+o.toString());
        return o;
    }
}

